<template>
	<view class="page-content">
		<u-loading-page :loading="loading" bg-color="#e8e8e8"></u-loading-page>
		<u--form labelWidth="auto" labelAlign="left" labelPosition="left" :model="detailform" :rules="rules"
			ref="form1">

			<u-form-item v-if="detailform.prodType == '智能设备'" label="产品序列号" prop="prodSn" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.prodSn"></u--text>
			</u-form-item>

			<u-form-item label="产品编码" prop="prodId" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.prodId"></u--text>
			</u-form-item>

			<u-form-item label="类别" prop="prodType" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.prodType"></u--text>
			</u-form-item>

			<u-form-item label="产品名称" prop="prodName" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.prodName"></u--text>
			</u-form-item>

			<u-form-item label="产品图片" prop="prodPic" borderBottom ref="item1">
				<imageUpload readonly v-model="detailform.prodPic" style="float:right;" />
			</u-form-item>

			<u-form-item label="产品规格" prop="prodSpeci" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.prodSpeci"></u--text>
			</u-form-item>

			<u-form-item label="数量" prop="prodNum" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.prodNum"></u--text>
			</u-form-item>

			<u-form-item label="备注" prop="remarke" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.remarke"></u--text>
			</u-form-item>

			<u-form-item label="改造前照片" prop="beforeImg" borderBottom ref="item1">
				<imageUpload readonly v-model="detailform.beforeImg" />
			</u-form-item>

			<u-form-item label="改造后照片" prop="afterImg" borderBottom ref="item1">
				<imageUpload readonly v-model="detailform.afterImg" />
			</u-form-item>

		</u--form>

		<u-row customStyle="margin:10px">
			<u-col span="12">
				<u-button class="custom-style" @click="handel_edit_click" type="success" size="small">编辑
				</u-button>
			</u-col>
		</u-row>

		<!-- 	<u-row customStyle="margin:10px">
			<u-col span="12">
				<u-button v-if="detailform.prodType == '智能设备'" class="custom-style" @click="handel_history_click"
					size="small">历史数据查询
				</u-button>
			</u-col>
		</u-row> -->

		<!-- <u-row customStyle="margin:10px">
			<u-col span="12">
				<u-button class="custom-style" @click="handel_delete_click" :disabled="disabled_Delete" type="error"
					size="small">删除
				</u-button>
			</u-col>
		</u-row>
		<u-modal :show="show" :showCancelButton="true" :content="content" @confirm="handle_confirmDelete_click"
			@cancel="handle_confirmCancel_click">
		</u-modal> -->
	</view>
</template>

<script>
	import {
		GetDatetime
	} from "@/utils/stringFormat.js";

	import {
		listSlhgzresqjl,
		getSlhgzresqjl,
		delSlhgzresqjl,
		addSlhgzresqjl,
		updateSlhgzresqjl,
	} from "@/api/elder/serviceApply.js";

	import {
		listSlhgzsbwcqk,
		getSlhgzsbwcqk,
		delSlhgzsbwcqk,
		addSlhgzsbwcqk,
		updateSlhgzsbwcqk,
	} from "@/api/elder/serviceApply_GZSG.js";

	import {
		QueryDeviceInstallList,
		addDeviceInstall,
		updateDeviceInstall,
		getDeviceInstall,
		delDeviceInstall,
		QueryDeviceInstallHistory,
		QueryDeviceInstallDev
	} from "@/api/elder/DeviceInstall";
	import
	imageUpload
	from "@/components/image-upload/multiple.vue";
	//from "@/components/image-upload/single.vue";
	import {
		transformPostBody,
		transformRequestURL
	} from "@/utils/requestParams.js";


	export default {
		components: {
			imageUpload
		},
		data() {
			return {
				uuid: null, //项目uuid
				shenqingId: null, //服务申请id号
				taskId: null,

				loading: false, //加载中
				show: false, //删除确认窗口
				content: "确认删除此条老人信息?",
				rules: {},

				serviceApply: {
					searchValue: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					remark: null,
					params: {},
					id: null,
					taskId: null,
					taskTypeCode: null,
					taskTypeName: null,
					begName: null,
					begTime: null,
					serverType: null,
					serverId: null,
					serverName: null,
					elderId: null,
					elderName: null,
					elderIdno: null,
					taskProvince: null,
					taskCity: null,
					taskDistrict: null,
					taskTown: null,
					taskVillage: null,
					taskStreet: null,
					taskRegisterAdd: null,
					taskLongitude: null,
					taskLatitude: null,
					planStartTime: null,
					planEndTime: null,
					startTime: null,
					endTime: null,
					status: null,
					taskDetail: null,
					isSelfSign: null,
					elderSign: null,
					approveName: null,
					approveResult: null,
					approveOpinion: null,
					star: null,
					appraise: null,
					realLongitude: null,
					realLatitude: null,
					attribute1: null,
					attribute2: null,
					attribute3: null,
					attribute4: null,
					attribute5: null,
					attribute6: null,
					attribute7: null,
					attribute8: null,
					attribute9: null,
					attribute10: null,
					attribute11: null,
					attribute12: null,
					attribute13: null,
					attribute14: null,
					attribute15: null,
					attribute16: null,
					attribute17: null,
					attribute18: null,
					attribute19: null,
					attribute20: null,
					attribute21: null,
					attribute22: null,
					attribute23: null,
					attribute24: null,
					attribute25: null,
					attribute26: null,
					attribute27: null,
					attribute28: null,
					attribute29: null,
					attribute30: null,
					attribute31: null,
					attribute32: null,
					defaultCommision: null,
					realCommision: null,
					commisionPay: null,
					prodToprice: null,
					prodRealpay: null,
					prodPay: null,
				},
				detailform: {
					searchValue: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					remark: null,
					params: {},
					uuid: null,
					orderId: null,
					prodId: null,
					prodType: null,
					prodName: null,
					prodPic: null,
					prodSpeci: null,
					prodNum: null,
					price: null,
					totalPrice: null,
					isNece: null,
					remarke: null,
					devBelong: null,
					listBelong: null,
					elderUuid: null,
					taskId: null,
					isConfirm: null,
					comTime: null,
					beforeImg: null,
					afterImg: null,
				},
			};
		},
		onLoad: function(options) {
			console.log("options", options);
			this.uuid = options.uuid; //将老人id保存
			this.shenqingId = options.shenqingId;
			this.taskId = options.taskId;
		},
		computed: {
			disabled_Delete() {
				return !this.$auth.hasRole("admin");
			},
		},
		onShow() {
			this.getList(); //切换到此页面后刷新数据
		},
		methods: {
			getList() {
				this.loading = true;
				console.log("getList", this.uuid);
				getSlhgzsbwcqk(this.uuid).then((response) => {
					this.loading = false;
					this.detailform = Object.assign({}, this.detailform, response.data);
				});
			},

			//跳转编辑页面
			handel_edit_click() {
				//检验是否已经签到
				listSlhgzresqjl({
					"pageNum": 1,
					"pageSize": 1000,
					"taskId": this.detailform.taskId
				}).then((response) => {
					console.log("签到校验", response);
					this.serviceApply = response.rows[0]
					if (!this.serviceApply.startTime) {
						uni.$u.toast("请先签到");
					} else {
						this.$tab.navigateTo('/pages/GaiZaoShiGong/GZSG/edit?uuid=' + this.uuid //明细uuid
							+
							'&taskId=' + this.taskId //taskId
							+
							'&shenqingId=' + this.shenqingId //申请单id字段
						)
					}
				})
			},

			//删除设备信息
			handel_delete_click() {
				this.show = true;
			},

			//确认删除
			handle_confirmDelete_click() {
				this.loading = true;
				delRTInfo([this.uuid])
					.then((response) => {
						uni.$u.toast("删除成功");
						this.loading = false;
						console.log("delRTInfo", response);
						this.show = false;
						this.$tab.navigateBack();
					})
					.catch((errors) => {
						console.log("errors", errors, this.uuid);
						uni.$u.toast("删除失败");
					});
			},

			//取消删除
			handle_confirmCancel_click() {
				this.show = false;
			},
			// //历史数据查询
			// handel_history_click() {
			// 	console.log('this.detailform', this.detailform)
			// 	//没法获取id进入，需要换成其他方法
			// 	// QueryDeviceInstallList({
			// 	// 		pageNum: 1,
			// 	// 		pageSize: 15
			// 	// 	},
			// 	// 	transformRequestURL({
			// 	// 		deviceNum: this.detailform.prodSn
			// 	// 	})
			// 	// ).then((response) => {
			// 	// 	console.log('handel_history_click', response)
			// 	// 	this.$tab.navigateTo('/pages/DeviceInstall/history?id=' + response.rows[0].id)
			// 	// });
			// },
		},
	};
</script>

<style lang="scss">
	page {
		background-color: white;
		display: flex;
		justify-content: center;
	}

	.page-content {
		width: 93%;
	}

	.custom-style {
		width: 80%;
		font-weight: bolder;
		font-size: 17px;
	}
</style>